//
//  BMASearch.m
//  LZMusicPlayer
//
//  Created by wulanzhou on 2016/11/1.
//  Copyright © 2016年 wulanzhou. All rights reserved.
//

#import "BMASearch.h"
#import "NSString+CZExtend.h"

@implementation BMASearch

/**
 * 热门关键字
 * @return
 */
- (NSString *) hotWord{
    
    NSMutableString *sb = [[NSMutableString alloc] initWithString:[self baseURLString]];
    [sb appendString:@"&method=baidu.ting.search.hot"];
    return sb;
}

/**
 * 搜索建议
 * @param input	输入词
 * @return
 */
- (NSString *) searchSugestion:(NSString*)query{
    
    NSMutableString *sb = [[NSMutableString alloc] initWithString:[self baseURLString]];
    [sb appendString:@"&method=baidu.ting.search.catalogSug"];
    [sb appendFormat:@"&query=%@",[query URLEncode]];

    return sb;
}

/**
 * 搜歌词
 * @param songname	歌名
 * @param artist	艺术家
 * @return
 */
- (NSString *) searchLrcPic:(NSString*)songname artist:(NSString *)artist{
    
    NSTimeInterval  ts=[[NSDate date] timeIntervalSince1970];
    NSString *query =[NSString stringWithFormat:@"%@$$%@",[songname URLEncode],[artist URLEncode]];
    
    
    //String query = encode(songname) +"$$"+ encode(artist);
    //String e = AESTools.encrpty("query="+songname +"$$"+ artist+"&ts="+ts);
    NSString *e=[[NSString stringWithFormat:@"query=%@$$%@&ts=%f",songname,artist,ts] stringFromMD5];
    
    NSMutableString *sb = [[NSMutableString alloc] initWithString:[self baseURLString]];
    [sb appendString:@"&method=baidu.ting.search.lrcpic"];
    [sb appendFormat:@"&query=%@",[query URLEncode]];
    [sb appendFormat:@"&ts=%f",ts];
    [sb appendString:@"&type=2"];
    [sb appendFormat:@"&e=%@",e];
    return sb;
}

/**
 * 合并搜索结果，用于搜索建议中的歌曲
 * @param query
 * @return
 */
- (NSString *) searchMerge:(NSString*)query pageNo:(int)pageNo pageSize:(int)pageSize{
    
    NSMutableString *sb = [[NSMutableString alloc] initWithString:[self baseURLString]];
    [sb appendString:@"&method=baidu.ting.search.merge"];
    [sb appendFormat:@"&query=%@",[query URLEncode]];
    [sb appendFormat:@"&page_no=%d",pageNo];
    [sb appendFormat:@"&page_size=%d",pageSize];
    [sb appendString:@"&type=-1&data_source=0"];
    
    return sb;
}

/**
 * 搜索伴奏
 * @param query	关键词
 * @param pageNo	页码
 * @param pageSize	每页数量，也是返回数量
 * @return
 */
- (NSString *) searchAccompany:(NSString*)query pageNo:(int)pageNo pageSize:(int)pageSize{
    
    NSMutableString *sb = [[NSMutableString alloc] initWithString:[self baseURLString]];
    [sb appendString:@"&method=baidu.ting.learn.search"];
    [sb appendFormat:@"&query=%@",[query URLEncode]];
    [sb appendFormat:@"&page_no=%d",pageNo];
    [sb appendFormat:@"&page_size=%d",pageSize];
    
    return sb;
}

@end
